﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using System.Web;
using System.Web.Services;
using System.Web.UI.WebControls;


namespace wdss.WebServices
{
    /// <summary>
    /// Summary description for UploadCheckService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class UploadCheckService : System.Web.Services.WebService
    {

        public UploadCheckService()
        {
        }
        public void insertIntoTable(int userid, string docname, FileUpload fileUploadDoc)
        {
            int docid = 0;
            String fileExtension = System.IO.Path.GetExtension(fileUploadDoc.FileName).ToLower();
            SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString);
            String query  = "select doc_ID from Document where doc_title like \'"+docname + fileExtension+"\'";
            
            SqlCommand command = new SqlCommand(query, connect);
            SqlDataAdapter adapter = new SqlDataAdapter(command);

            try
            {
                connect.Open();
                docid = (int)command.ExecuteScalar();
                connect.Close();
            }
            catch (Exception ex)
            { }
            
            SqlCommand command1 = new SqlCommand("insert into Doc_Checked values(" + docid + "," + userid + "," + "0)", connect);
            SqlDataAdapter adapter1 = new SqlDataAdapter(command1);
            try
            {
                connect.Open();
                command1.ExecuteNonQuery();
                connect.Close();
                connect.Dispose();
            }
            catch (Exception ex)
            { }
        }
    }
}
